﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
@section header{
    <link href="@Url.Content("~/lib/bootstrap.table/1.12.0/extensions/editable/bootstrap-editable.css")" rel="stylesheet" type="text/css">
    <script src='@Url.Content("~/lib/bootstrap.table/1.12.0/extensions/editable/bootstrap-editable.min.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/lib/bootstrap.table/1.12.0/extensions/editable/bootstrap-table-editable.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/lib/bootstrap.table/1.12.0/extensions/editable/bootstrap-datepicker.zh-CN.js")' type="text/javascript"></script>
}
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/DemoManage/Table/GetPageListJson")';
        $('#gridTable').ysTable({
            url: queryUrl,
            onEditableSave: onEditableSave,
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: '用户编号' },
                {
                    field: 'RealName', title: '用户姓名',
                    editable: {
                        type: 'text',
                        emptytext: "【用户姓名】为空",
                        validate: function (value) {
                            if (value.length > 20) {
                                return '用户姓名不能超过20个字符';
                            }
                            if (value.length == 0) {
                                return '用户姓名不能为空';
                            }
                        }
                    }
                },
                { field: 'Mobile', title: '手机' },
                { field: 'Email', title: '邮箱' },
                {
                    field: 'Birthday', title: '生日',
                    editable: {
                        type: 'date',
                        emptytext: "【生日】为空",
                        clear: false,
                        datepicker: { language: 'zh-CN' },//中文支持
                        validate: function (value) {
                            if (value == '') { return '生日不能为空!' }
                        }
                    }
                },
                {
                    field: 'UserStatus', title: '状态',
                    align: 'center',
                    editable: {
                        type: 'select',
                        source: [{
                            value: 0,
                            text: "停用"
                        }, {
                            value: 1,
                            text: "正常"
                        }]
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="#"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="#"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function onEditableSave(field, row, oldValue, $el) {
        alert("字段名：" + field + "，当前值：" + row[field] + "，旧值：" + oldValue);
    }
</script>
